package com.tony.study.thread;

/**
 * Created with IntelliJ IDEA.
 *
 * @Title: YiedDemo01
 * @Auther: 皮蛋布丁
 * @Date: 2021/10/31/15:08
 * @Description: 测试礼让线程（礼让不一定成功，看cpu）
 */
public class YieldDemo01 {

    public static void main(String[] args) {
        MyYield yield = new MyYield();

        new Thread(yield,"a").start();
        new Thread(yield,"b").start();
    }

}

class MyYield implements Runnable {

    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName()+"线程开始执行");
        Thread.yield(); //礼让
        System.out.println(Thread.currentThread().getName()+"线程停止执行");
    }
}
